package org.zpmis.api.http;

import org.springframework.validation.annotation.Validated;
import org.zpmis.api.business.ReturnVisitWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.customer.qo.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
* created with CodeGenerator
* description:
* @author  Yang
* date: 2021-6-2
* time: 14:48:50
*/
@RestController
@RequestMapping("/visit")
@Slf4j
public class ReturnVisitController extends BaseController{

    @Resource
    private ReturnVisitWebService returnVisitWebService;


    /**
     * 查询意向回访记录
     * @param queryReturnVisitRecordQo
     * @return
     */
    @PostMapping("/queryReturnVisitRecord")
    public PlatformResult queryReturnVisitRecord(@Validated @RequestBody QueryReturnVisitRecordQo queryReturnVisitRecordQo){
        try {
            return PlatformResult.success(returnVisitWebService.queryReturnVisitRecord(queryReturnVisitRecordQo));
        } catch (Exception e) {
            log.error("[IntentionController]---queryReturnVisitRecord--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 新增回访记录
     * @param addReturnVisitQo
     * @return
     */
    @PostMapping("/addReturnVisit")
    public PlatformResult addReturnVisit(@Validated @RequestBody AddReturnVisitQo addReturnVisitQo){
        try {
            returnVisitWebService.addReturnVisit(addReturnVisitQo);
        } catch (BusinessException e) {
            log.error("[IntentionController]---addReturnVisit--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        }catch (Exception e) {
            log.error("[IntentionController]---addReturnVisit--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }


    /**
     * 修改回访记录
     * @param editReturnVisitQo
     * @return
     */
    @PostMapping("/editReturnVisit")
    public PlatformResult editReturnVisit(@Validated @RequestBody EditReturnVisitQo editReturnVisitQo){
        try {
            returnVisitWebService.editReturnVisit(editReturnVisitQo);
        } catch (BusinessException e) {
            log.error("[IntentionController]---editReturnVisit--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[IntentionController]---editReturnVisit--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 回访记录列表查询
     * @param returnVisitListQo
     * @return
     */
    @PostMapping("/returnVisitList")
    public PlatformResult returnVisitList(@RequestBody ReturnVisitListQo returnVisitListQo){
        try {
            return PlatformResult.success(returnVisitWebService.returnVisitList(returnVisitListQo));
        } catch (BusinessException e) {
            log.error("[IntentionController]---returnVisitList--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[IntentionController]---returnVisitList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 获取回访详情
     * @param getVisitDetailQo
     * @return
     */
    @PostMapping("/getVisitDetail")
    public PlatformResult getVisitDetail(@Validated @RequestBody GetVisitDetailQo getVisitDetailQo){
        try {
            return PlatformResult.success(returnVisitWebService.getVisitDetail(getVisitDetailQo));
        } catch (BusinessException e) {
            log.error("[ReturnVisitController]---getVisitDetail--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[ReturnVisitController]---getVisitDetail--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
